package com.slkj.shilixiaoyuanapp.ui.main.community;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.entity.CommunityEntity;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created  on 2018-08-27
 *
 * @author 唐开阔
 * @describe
 */
public class LikePeopleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    List<CommunityEntity.FabulousUser> data;
   CommunityAdapter.CallBack callBack ;
    public LikePeopleAdapter(List<CommunityEntity.FabulousUser> data) {
        this.data = data;
    }



    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_like_people, parent, false));

    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        Holder  viewHoder = (Holder) holder;
        viewHoder.bindData(position);
    }

    @Override
    public int getItemCount() {
        return data.size() + 1;
    }

    class Holder extends RecyclerView.ViewHolder {
        TextView tvName;
        ImageView imgLike;
        public Holder(View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tv_name);
            imgLike = itemView.findViewById(R.id.img_like);
        }
        public void bindData(int pos){
            if (pos == 0) {
                tvName.setVisibility(View.GONE);
                imgLike.setVisibility(View.VISIBLE);
                tvName.setText("");
            } else {
                CommunityEntity.FabulousUser item = data.get(pos - 1);
                tvName.setVisibility(View.VISIBLE);
                imgLike.setVisibility(View.GONE);
                boolean isEnd = pos == data.size();
                tvName.setText(isEnd ? item.getName() : item.getName() + ",");
            }

        }

    }
}
